package com.wframe.project.former.web.floor;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.wframe.project.former.dataservices.floor.UiFloorService;
import org.apache.commons.lang.StringUtils;

import com.frame.database.JdataBean;
import com.frame.database.PageResult;
import com.frame.pageform.DataPageForm;
import com.frame.pageform.annotation.Login;

@Login
public class UiFloorProductPage extends DataPageForm {

    private static UiFloorService uiFloorService = UiFloorService.getIntance();
    private JdataBean bean;

    @Override
    public String execute() throws Exception {
        setResultList_(uiFloorService.queryFloorItem(bean.getString("panelId")));
        return "/webadmin/floor/floorPanelItems.jsp";
    }

    @Override
    public String show() throws Exception {
        if (bean != null && StringUtils.isNotBlank(bean.getString("id")))
            bean = uiFloorService.getChannel(bean.getString("id"));
        return "/webadmin/floor/floorPanelItemsEdit.jsp";
    }

    @Override
    public String toDel() throws Exception {
        return getJsonObject().toString();
    }

    @Override
    public boolean toUpdate() throws Exception {
        JdataBean bean = getBean();
        bean.put("create_time",new Date());
        uiFloorService.saveChannel(bean);
        getJsonObject().getJsonPage().showOkMsg("修改成功");
        getJsonObject().getJsonPage().closeWin("ok");
        return false;
    }

    public String panelProductsShow() throws Exception {
        if (bean != null && StringUtils.isNotBlank(bean.getString("id")))
            bean = uiFloorService.getFloorItem(bean.getString("id"));
        return "/webadmin/floor/floorPanelProductsEdit.jsp";
    }

    public String floorCategorSave() throws Exception {
        String[] proids = null;
        if (StringUtils.isNotBlank(bean.getString("proids"))) proids = bean.getString("proids").split(",");
        bean.remove("proids");
        uiFloorService.saveFloorItem(bean.getString("id"), proids);
        getJsonObject().getJsonPage().showOkMsg("保存成功");
        getJsonObject().getJsonPage().closeWin("ok");
        return getJsonObject().toString();
    }

    public String floorCategorDel() throws Exception {
        uiFloorService.delFloorItem(bean.getString("id"));
        return getJsonObject().toString();
    }

    public String loadFloorProducts() throws Exception {
        int pageno = 1;
        int size = 20;
        if (StringUtils.isNotBlank(getRequest().getParameter("page")))
            pageno = new Integer(getRequest().getParameter("page"));
        if (StringUtils.isNotBlank(getRequest().getParameter("rows")))
            size = new Integer(getRequest().getParameter("rows"));
        PageResult pr = uiFloorService.queryFloorProduct(bean, size, pageno);
        getJsonObject().put("total", pr.getResultCount());
        getJsonObject().put("rows", pr.getList());
        return getJsonObject().toString();
    }

    public String updatestatus() throws Exception {
        if (getPrimaryKey_() != null) {
            for (String id : getPrimaryKey_()) {
                uiFloorService.updatestatus(id, bean.getInt("status"));
            }
        }
        return getJsonObject().toString();
    }

    public JdataBean getBean() {
        return bean;
    }

    public void setBean(JdataBean bean) {
        this.bean = bean;
    }

}
